package com.wooophone.buyi.web.action;

import org.htmlparser.util.ParserException;
import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator;
import com.opensymphony.xwork2.validator.annotations.Validations;
import com.wooophone.buyi.bean.GatherImage;
import com.wooophone.buyi.biz.PinBiz;
import com.wooophone.common.util.JsonSfUtil;
import com.wooophone.common.util.MatcheUtil;
import com.wooophone.common.web.action.BaseAction;

public class PinAction extends BaseAction {
	
	private static final long serialVersionUID = 1L;
	
	@Autowired
	private PinBiz pinBiz;
	
	private String url;

	/**
	 * 采集图片
	 * @return
	 */

	@Validations(requiredStrings = {
			@RequiredStringValidator(fieldName = "url", message = "url必填!")
			},fieldExpressions={
			
		})
	public String gatherImage(){
		try {
			if(MatcheUtil.matcheUrl(url)){
				GatherImage gatherImage = pinBiz.gatherImage(url);
				String json = JsonSfUtil.toJsonByJsonLib(gatherImage);
				return ajax(toCallBackString(json));
			}else{
				return ajax(toCallBackErrorString("不合法的url"));
			}
		} catch (ParserException e) {
			e.printStackTrace();
			return ajax(Status.error,"无法采集");
		}catch (Exception e) {
			e.printStackTrace();
			return ajax(Status.error,e.getMessage());
		}
	}

	public void setPinBiz(PinBiz pinBiz) {
		this.pinBiz = pinBiz;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}
}
